﻿using System;
using System.IO;
using System.Net;
using System.Linq;
using System.Text;
using System.Activities;
using System.Activities.Expressions;
using System.Activities.Presentation.PropertyEditing;
using System.Activities.Statements;
using System.Collections.Generic;
using System.ComponentModel;
using System.Xml;

namespace Vision.Core.ActivityComponents.SharePoint
{
    /// <summary>
    /// 
    /// </summary>
    public class SPListAddAttachment : NativeActivity
    {
        /// <summary>
        /// 
        /// </summary>
        [DefaultValue("")]
        [Category("Input")]        
        public InArgument<string> ListName { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [DefaultValue("")]
        [Category("Input")]        
        public InArgument<string> ListItemId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [DefaultValue("")]
        [Category("Input")]        
        public InArgument<string> FileName { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [DefaultValue("")]
        [Category("Input")]        
        public InArgument<byte[]> FileData { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(NativeActivityContext context)
        {
            List<object> methodParams = new List<object>();
                        
            Components.DynamicWebService spService = (Components.DynamicWebService)context.Properties.Find("F1634880-5000-11E0-A748-B487DFD72085");
            if (spService != null){                                
                methodParams.Clear();
                methodParams.Add(this.ListName.Get(context));
                methodParams.Add(this.ListItemId.Get(context));
                methodParams.Add(this.FileName.Get(context));
                methodParams.Add(this.FileData.Get(context));                                                
                spService.InvokeMethod<object>("AddAttachment", methodParams);    
            }                        
        }
    }
}
